﻿#include "FITKAbstractSEAFace.h"
#include "FITKSEAFlatCurvedFace.h"
#include "FITKSEASubSysModelProp.h"
#include "FITKAcousticsTriangles.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"

namespace Acoustics
{

    FITKAbstractSEAFace::FITKAbstractSEAFace()
    {
        //几何属性
        _modelProp = new FITKSEASubSysModelProp(this);
        //创建三角形管理器
        _triMesh = new FITKAcousticsTriangles;
    }

    FITKAbstractSEAFace::~FITKAbstractSEAFace()
    {
        if (_modelProp) delete _modelProp;
        if (_triMesh) delete _triMesh;
    }

 

    Acoustics::FITKAbstractSEASubSys::SEASubSysType FITKAbstractSEAFace::getFaceType()
    {
        return FITKAbstractSEASubSys::SEASubSysType::SEASSNone;
    }

    bool FITKAbstractSEAFace::updateModelProp()
    {
        if (_modelProp == nullptr) return false;
        bool OK = _modelProp->updateModelProp();
        return OK;
    }

    FITKSEASubSysModelProp* FITKAbstractSEAFace::getModelPorp()
    {
        return _modelProp;
    }

    void FITKAbstractSEAFace::setNodes(const QList<FITKAbstractSEASubSysWithNodes::SubSysNode>& nodes)
    {
        _nodes = nodes;
    }


    QList<Acoustics::FITKAbstractSEASubSysWithNodes::SubSysNode> FITKAbstractSEAFace::getNodes()
    {
        return _nodes;
    }

    Acoustics::FITKAcousticsTriangles* FITKAbstractSEAFace::getTriangleMesh()
    {
        return _triMesh;
    }

    QList<int> FITKAbstractSEAFace::getNodeIDs() const
    {
        QList<int> ids;
        for (FITKAbstractSEASubSysWithNodes::SubSysNode node : _nodes)
            ids.append(node._id);

        return ids;
    }

  

    bool FITKAbstractSEAFace::isContainsNode(const int id) const
    {
        QList<int> nodes = this->getNodeIDs();
        return nodes.contains(id);
    }

    void FITKAbstractSEAFace::addConnector(FITKAbstractSEASubSys* obj)
    {
        if (nullptr == obj || _connector.contains(obj)) return;
        _connector.append(obj);
    }

    void FITKAbstractSEAFace::removeConnector(FITKAbstractSEASubSys* obj)
    {
        if (nullptr == obj || !_connector.contains(obj)) return;
        _connector.removeAll(obj);
        //全部移除后释放对象
        if (_connector.isEmpty()) delete this;
    }
 
    Acoustics::FITKAbstractSEASubSys* FITKAbstractSEAFace::getConnectedSubSys(const int & id)
    {
        //遍历对象
        for (FITKAbstractSEASubSys* s : _connector)
        {
            if(s == nullptr) continue;
            //查找ID
            if (id == s->getDataObjectID())
                return s;
        }
        return nullptr;
    }

    Acoustics::FITKAbstractSEASubSys* FITKAbstractSEAFace::getAConnectedSubSys(FITKAbstractSEASubSys::SEASubSysType t)
    {
        //遍历对象
        for (FITKAbstractSEASubSys* s : _connector)
        {
            if (s == nullptr) continue;
            //类型查找
            if (t == s->getSEASubSysType())
                return s;
        }
        return nullptr;
    }

    Acoustics::FITKAbstractSEASubSys* FITKAbstractSEAFace::getAConnectedShellSubSys()
    {

        //遍历对象
        for (FITKAbstractSEASubSys* s : _connector)
        {
            if (s == nullptr) continue;
            //类型查找
            if (FITKAbstractSEASubSys::SEASubSysType::SEAFlatPlate == s->getSEASubSysType() ||
                FITKAbstractSEASubSys::SEASubSysType::SEASinglyCurvedShell == s->getSEASubSysType() ||
                FITKAbstractSEASubSys::SEASubSysType::SEADoublyCurvedShell == s->getSEASubSysType())
                return s;
        }
        return nullptr;
    }

    void FITKAbstractSEAFace::setOutsideNCTID(int id)
    {
        //设置外部声学包
        _outsideNCTID = id;
    }

    int FITKAbstractSEAFace::getOutsideNCTID()
    {
        //获取外部声学包id
        return _outsideNCTID;
    }

    FITKAcousticsAbsNCT* FITKAbstractSEAFace::getOutsideNCT()
    {
        //获取外部声学包
        return FITKDATAREPO->getTDataByID<FITKAcousticsAbsNCT>(_outsideNCTID);
    }

    void FITKAbstractSEAFace::setInsideNCTID(int id)
    {
        //设置内部声学包
        _insideNCTID = id;
    }

    int FITKAbstractSEAFace::getInsideNCTID()
    {
        //获取内部声学包id
        return _insideNCTID;
    }

    FITKAcousticsAbsNCT* FITKAbstractSEAFace::getInsideNCT()
    {
        //获取内部声学包
        return FITKDATAREPO->getTDataByID<FITKAcousticsAbsNCT>(_insideNCTID);
    }

    void FITKAbstractSEAFace::setOutsideNCTCoveredArea(double percentage)
    {
        //设置外部声学包覆盖率
        _outsideNCTCoveredArea = percentage;
    }

    double FITKAbstractSEAFace::getOutsideNCTCoveredArea()
    {
        //获取外部声学包覆盖率
        return _outsideNCTCoveredArea;
    }

    void FITKAbstractSEAFace::setInsideNCTCoveredArea(double percentage)
    {
        //设置内部声学包覆盖率
        _insideNCTCoveredArea = percentage;
    }

    double FITKAbstractSEAFace::getInsideNCTCoveredArea()
    {
        //获取内部声学包覆盖率
        return _insideNCTCoveredArea;
    }

    void FITKAbstractSEAFace::setFEFace(bool fe)
    {
        _isFEFace = fe;
    }

    bool FITKAbstractSEAFace::isFEFace()
    {
        return _isFEFace;
    }

    Acoustics::FITKAbstractSEAFace* FITKSEAFaceManager::CreateSEAFace(FITKAbstractSEASubSys::SEASubSysType t)
    {
        //只对板、梁类型有效
        switch (t)
        { 
        case  FITKAbstractSEASubSys::SEABeam:
            return new FITKSEABeamFace;
        case Acoustics::FITKAbstractSEASubSys::SEAFlatPlate:
            return new FITKSEAFlatPlateFace;
        case Acoustics::FITKAbstractSEASubSys::SEASinglyCurvedShell:
            return new FITKSEASinglyCurvedFace;
        case Acoustics::FITKAbstractSEASubSys::SEADoublyCurvedShell:
            return new FITKSEADoublyCurvedFace;
        default:
            break;
        }
        //其他返回空
        return nullptr;
    }

}



